import type { RouteRecordRaw } from "vue-router";
import NotFound from "@/views/404.vue";

import { testRoutes } from "./test";
import { userRoutes} from "./user";
import { productRoutes } from "./product";
import {fileRoutes} from "./file";

// 定义路由 meta 类型增强
declare module "vue-router" {
  interface RouteMeta {
    title?: string; // 页面标题（必须）
    icon?: string; // 图标类名（可选）
    fixed?: boolean; // 是否固定在标签页（可选）
    hidden?: boolean; // 是否隐藏菜单（可选）
    breadcrumb?: Array<{
      // 面包屑配置（可选）
      title: string;
      path?: string; // 可点击的面包项需要 path
    }>;
    isBasic?: boolean; // 是否基础路由（如登录页）
  }
}

export const baseRoutes: RouteRecordRaw[] = [
  
  // 其他基础路由...
  {
    path: "/",
    name: "MainLayout",
    component: () => import("@/components/layout/index.vue"),
    meta: {
      title: "404",
      requiresAuth: true,
    },
    redirect: (to) => (to.path === "/" ? "/home" : "/404"), // 添加这行实现自动重定向
    children: [
      {
        path: "/home",
        name: "Home",
        component: () => import("@/views/Home.vue"),
        meta: {
          title: "首页",
          fixed: true,
          requiresAuth: true,
          icon: "HomeFilled",
          breadcrumb: [{ title: "首页", path: "/home" }],
        },
      },
      {
        path: "/dashboard/workplace",
        name: "Workspace",
        component: () => import("@/views/dashboard/workspace.vue"),
        meta: {
          title: "工作台",
          fixed: true,
          requiresAuth: true,
          icon: "dashboard",
        },
      },
      {
        path: "/dashboard/analytics",
        name: "Analytics",
        component: () => import("@/views/dashboard/analytics.vue"),
        meta: { title: "分析页", fixed: true, requiresAuth: true, icon: "" },
      },
      {
        path: "/visualization/screen",
        name: "Screen",
        component: () => import("@/views/visualization/screen.vue"),
        meta: { title: "数据大屏", fixed: true, requiresAuth: true, icon: "" },
      },
      {
        path: "/visualization/map",
        name: "Map",
        component: () => import("@/views/visualization/D3Map.vue"),
        meta: { title: "D3地图", fixed: true, requiresAuth: true, icon: "" },
      },
      {
        path: "/list",
        name: "list",
        component: () => import("@/views/List.vue"),
        meta: { title: "列表页", requiresAuth: true, icon: "" },
      },
      {
        path: "/details",
        name: "details",
        component: () => import("@/views/Details.vue"),
        meta: { title: "详情页面", requiresAuth: true, icon: "" },
      },
      {
        path: "/verify/slider",
        name: "slider",
        component: () => import("@/views/verify/slider.vue"),
        meta: { title: "图形滑块验证", requiresAuth: true, icon: "" },
      },
      {
        path: "/verify/index",
        name: "Verify",
        component: () => import("@/views/verify/index.vue"),
        meta: { title: "验证测试页面", requiresAuth: true, icon: "" },
      },
      {
        path: "/setting",
        name: "Setting",
        component: () => import("@/views/system/setting/index.vue"),
        meta: { title: "系统设置", requiresAuth: true, icon: "" },
      },
      // 用户管理相关路由
      ...userRoutes,
      // 文件管理相关路由
      ...fileRoutes,

      // 商品管理相关路由
      ...productRoutes,
      {
        path: "/:pathMatch(.*)*", // 匹配所有未定义的路由
        name: "NotFound",
        meta: { title: "404页面", icon: "" },
        component: NotFound,
      },
      ...testRoutes,
    ],
  },
];
